<template xmlns:el-image="http://www.w3.org/1999/html">
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['tenant:info:edit']"
        >审核</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="infoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="商户Id" align="center" prop="id" />
      <el-table-column label="商户名称" align="center" prop="name" />
      <el-table-column label="法人" align="center" prop="corporation" />
      <el-table-column label="地址" align="center" prop="address" />
      <el-table-column label="类型" align="center" prop="type" />
      <el-table-column label="状体" align="center" prop="status" />
      <el-table-column label="管理员工" align="center" prop="userId" />
      <el-table-column label="申请时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['tenant:info:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['tenant:info:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改商户对话框 -->
    <el-dialog :title="title" :v-if="open" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="商品类型" prop="name">
          <el-input v-model="form.type" placeholder="请输入type" />
        </el-form-item>
        <el-form-item label="商品名称" prop="name">
          <el-input v-model="form.name" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="法人" prop="corporation">
          <el-input v-model="form.corporation" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="省" prop="province">
          <el-input v-model="form.province" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="市" prop="city">
          <el-input v-model="form.city" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="县" prop="county">
          <el-input v-model="form.county" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="详细地址" prop="address">
          <el-input v-model="form.address" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="管理员" prop="userId">
          <el-input v-model="form.userId" placeholder="管理员" />
        </el-form-item>

        <el-form-item label="营业执照" prop="url">

                  <img :src="'http://127.0.0.1:80/'+this.form.url" style="width: 100px;height: 100px">

          <el-input v-model="form.url" placeholder="营业执照" />
        </el-form-item>
        <el-form-item label="统一信征码" prop="zheng">
          <el-input v-model="form.zheng" placeholder="请输入统一信征码" />
        </el-form-item>
        <el-form-item label="管理员" prop="zheng">
          <el-input v-model="form.userId" placeholder="请输入统一信征码" />
        </el-form-item>


        <!--<el-divider content-position="center">系统用户信息</el-divider>-->
        <!--<el-row :gutter="10" class="mb8">-->
        <!--  <el-col :span="1.5">-->
        <!--    <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAddSysUse">添加</el-button>-->
        <!--  </el-col>-->
        <!--  <el-col :span="1.5">-->
        <!--    <el-button type="danger" icon="el-icon-delete" size="mini" @click="handleDeleteSysUse">删除</el-button>-->
        <!--  </el-col>-->
        <!--</el-row>-->
        <!--<el-table :data="sysUseList" :row-class-name="rowSysUseIndex" @selection-change="handleSysUseSelectionChange" ref="sysUse">-->
        <!--  <el-table-column type="selection" width="50" align="center" />-->
        <!--  <el-table-column label="序号" align="center" prop="index" width="50"/>-->
        <!--  <el-table-column label="用户名" prop="username" width="150">-->
        <!--    <template slot-scope="scope">-->
        <!--      <el-input v-model="scope.row.username" placeholder="请输入用户名" />-->
        <!--    </template>-->
        <!--  </el-table-column>-->
        <!--  <el-table-column label="密码" prop="password" width="150">-->
        <!--    <template slot-scope="scope">-->
        <!--      <el-input v-model="scope.row.password" placeholder="请输入密码" />-->
        <!--    </template>-->
        <!--  </el-table-column>-->
        <!--  <el-table-column label="邮箱" prop="email" width="150">-->
        <!--    <template slot-scope="scope">-->
        <!--      <el-input v-model="scope.row.email" placeholder="请输入邮箱" />-->
        <!--    </template>-->
        <!--  </el-table-column>-->
        <!--  <el-table-column label="传真" prop="fax" width="150">-->
        <!--    <template slot-scope="scope">-->
        <!--      <el-input v-model="scope.row.fax" placeholder="请输入传真" />-->
        <!--    </template>-->
        <!--  </el-table-column>-->
        <!--  <el-table-column label="手机号" prop="mobile" width="150">-->
        <!--    <template slot-scope="scope">-->
        <!--      <el-input v-model="scope.row.mobile" placeholder="请输入手机号" />-->
        <!--    </template>-->
        <!--  </el-table-column>-->
        <!--  <el-table-column label="座机号" prop="landlineNumber" width="150">-->
        <!--    <template slot-scope="scope">-->
        <!--      <el-input v-model="scope.row.landlineNumber" placeholder="请输入座机号" />-->
        <!--    </template>-->
        <!--  </el-table-column>-->
        <!--  <el-table-column label="状态  0：禁用   1：正常" prop="status" width="150">-->
        <!--    <template slot-scope="scope">-->
        <!--      <el-select v-model="scope.row.status" placeholder="请选择状态  0：禁用   1：正常">-->
        <!--        <el-option label="请选择字典生成" value="" />-->
        <!--      </el-select>-->
        <!--    </template>-->
        <!--  </el-table-column>-->
        <!--  <el-table-column label="部门ID" prop="deptId" width="150">-->
        <!--    <template slot-scope="scope">-->
        <!--      <el-input v-model="scope.row.deptId" placeholder="请输入部门ID" />-->
        <!--    </template>-->
        <!--  </el-table-column>-->
        <!--  <el-table-column label="盐" prop="salt" width="150">-->
        <!--    <template slot-scope="scope">-->
        <!--      <el-input v-model="scope.row.salt" placeholder="请输入盐" />-->
        <!--    </template>-->
        <!--  </el-table-column>-->
        <!--  <el-table-column label="联系人" prop="contactMember" width="150">-->
        <!--    <template slot-scope="scope">-->
        <!--      <el-input v-model="scope.row.contactMember" placeholder="请输入联系人" />-->
        <!--    </template>-->
        <!--  </el-table-column>-->
        <!--  <el-table-column label="公寓运营商类型 1分散式 2 集中式" prop="apartmentOperatorType" width="150">-->
        <!--    <template slot-scope="scope">-->
        <!--      <el-select v-model="scope.row.apartmentOperatorType" placeholder="请选择公寓运营商类型 1分散式 2 集中式">-->
        <!--        <el-option label="请选择字典生成" value="" />-->
        <!--      </el-select>-->
        <!--    </template>-->
        <!--  </el-table-column>-->
        <!--  <el-table-column label="公司名称" prop="companyName" width="150">-->
        <!--    <template slot-scope="scope">-->
        <!--      <el-input v-model="scope.row.companyName" placeholder="请输入公司名称" />-->
        <!--    </template>-->
        <!--  </el-table-column>-->
        <!--  <el-table-column label="省" prop="province" width="150">-->
        <!--    <template slot-scope="scope">-->
        <!--      <el-input v-model="scope.row.province" placeholder="请输入省" />-->
        <!--    </template>-->
        <!--  </el-table-column>-->
        <!--  <el-table-column label="$comment" prop="city" width="150">-->
        <!--    <template slot-scope="scope">-->
        <!--      <el-input v-model="scope.row.city" placeholder="请输入$comment" />-->
        <!--    </template>-->
        <!--  </el-table-column>-->
        <!--  <el-table-column label="县" prop="country" width="150">-->
        <!--    <template slot-scope="scope">-->
        <!--      <el-input v-model="scope.row.country" placeholder="请输入县" />-->
        <!--    </template>-->
        <!--  </el-table-column>-->
        <!--  <el-table-column label="$comment" prop="addUserid" width="150">-->
        <!--    <template slot-scope="scope">-->
        <!--      <el-input v-model="scope.row.addUserid" placeholder="请输入$comment" />-->
        <!--    </template>-->
        <!--  </el-table-column>-->
        <!--  <el-table-column label="审核状态 1审核通过 2 审核不通 3 待审核 4未完善企业信息" prop="approvalFlag" width="150">-->
        <!--    <template slot-scope="scope">-->
        <!--      <el-input v-model="scope.row.approvalFlag" placeholder="请输入审核状态 1审核通过 2 审核不通 3 待审核 4未完善企业信息" />-->
        <!--    </template>-->
        <!--  </el-table-column>-->
        <!--</el-table>-->


      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listInfo, getInfo, delInfo, addInfo, updateInfo } from "@/api/tenant/info";

export default {
  name: "Info",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 子表选中数据
      checkedSysUse: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 商户表格数据
      infoList: [],
      // 系统用户表格数据
      sysUseList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询商户列表 */
    getList() {
      this.loading = true;
      listInfo(this.queryParams).then(response => {
        this.infoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        name: null,
        corporation: null,
        province: null,
        city: null,
        county: null,
        address: null,
        type: null,
        status: 0,
        userId: null,
        createTime: null,
        reserve1: null,
        reserve2: null,
        reserve3: null,
        reserve4: null,
        reserve5: null,
        url: null,
        zheng: null,
        headPicture: null,
        legalPersonName: null,
        certNum: null,
        certPicture: null,
        certPicture2: null,
        certPicture3: null,
        brandName: null,
        apartmentUrl: null,
        serviceHotline: null
      };
      this.sysUseList = [];
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加商户";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getInfo(id).then(response => {
        this.form = response.data;
        this.sysUseList = response.data.sysUseList;
        this.open = true;
        this.title = "修改商户";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.form.sysUseList = this.sysUseList;
          if (this.form.id != null) {
            updateInfo(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addInfo(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除商户编号为"' + ids + '"的数据项？').then(function() {
        return delInfo(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 系统用户序号 */
    rowSysUseIndex({ row, rowIndex }) {
      row.index = rowIndex + 1;
    },
    /** 系统用户添加按钮操作 */
    handleAddSysUse() {
      let obj = {};
      obj.username = "";
      obj.password = "";
      obj.email = "";
      obj.address = "";
      obj.fax = "";
      obj.mobile = "";
      obj.landlineNumber = "";
      obj.remark = "";
      obj.status = "";
      obj.deptId = "";
      obj.salt = "";
      obj.contactMember = "";
      obj.apartmentOperatorType = "";
      obj.companyName = "";
      obj.province = "";
      obj.city = "";
      obj.country = "";
      obj.addUserid = "";
      obj.approvalFlag = "";
      this.sysUseList.push(obj);
    },
    /** 系统用户删除按钮操作 */
    handleDeleteSysUse() {
      if (this.checkedSysUse.length == 0) {
        this.$modal.msgError("请先选择要删除的系统用户数据");
      } else {
        const sysUseList = this.sysUseList;
        const checkedSysUse = this.checkedSysUse;
        this.sysUseList = sysUseList.filter(function(item) {
          return checkedSysUse.indexOf(item.index) == -1
        });
      }
    },
    /** 复选框选中数据 */
    handleSysUseSelectionChange(selection) {
      this.checkedSysUse = selection.map(item => item.index)
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('tenant/info/export', {
        ...this.queryParams
      }, `info_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
